<?php 
$i=isset($_GET['i'])?$_GET['i']:1;
$page_group_id=3;
$query="SELECT COUNT(*) FROM tbl_page WHERE page_group_id=$page_group_id AND page_status=1";
$count=Db::mysql_query($query,FETCH_MODE_CELL);
if($i<1)
	Common::header_location(null,"index.php?page=$page&i=1");
else if($i>ceil($count/ROW_PER_PAGE))
	Common::header_location(null,"index.php?page=$page&i=".ceil($count/ROW_PER_PAGE));
$table=Db::mysql_query("SELECT * FROM tbl_page WHERE page_group_id=$page_group_id AND page_status=1 ORDER BY page_id DESC LIMIT ".(($i-1)*ROW_PER_PAGE).",".ROW_PER_PAGE,FETCH_MODE_TABLE);
?>


<style>
.post .post-title {padding-top: 42px}
</style>

<div class="post hentry uncustomized-post-template">
<div class="post_bottom">
<h2 class="post-title entry-title"></h2>
<div class="post_date"><?php echo Page::fetch_page_title($page);?></div>
<div class="entry">
	
	<?php foreach($table as $key=>$row){
	$page_title=$row['page_title'];
	?>
	<?php if($login==1 && $mode=='edit'){?>
		<input type='button' value='Xóa' style='float:right' class='i-delete' link='page=_delete&id=<?php echo $row['page_id']?>'/>
	<?php }?>
	<div class='item i-update' <?php echo $key==count($table)-1?" id='last' ":''?> link='page=_update-news&id=<?php echo $row['page_id']?>&group_id=<?php echo $page_group_id?>' >
		<div class='title' onclick="window.location='?page=<?php echo $row['page_name']?>&id=<?php echo $row['page_id']?>&group_id=3'">
			<?php echo $page_title;?><span>Ngày đăng: <?php echo date('d/m/Y')?>.</span>
		</div>
		<div class='quote'><?php echo $row['page_quote_'.$language];?></div>
		<div class="read_comments">
			<a href="?page=<?php echo $row['page_name']?>&id=<?php echo $row['page_id']?>&group_id=<?php echo $page_group_id;?>">Xem chi tiết</a>
		</div>
	</div>
	<?php }?>
	
</div>
<div class="read_comments">
	<div id='pagination'>
		<?php if($i>1){?><span id='prev' onclick="window.location='index.php?page=<?php echo $page;?>&i=<?php echo $i-1?>'" title='Trang trước'></span><?php }?>
				
		<?php 		
		$min=$i-5;
		$max=$i+4;
		if(ceil($count/$row_per_page)<10)
		{
			$min=1;
			$max=ceil($count/$row_per_page);				
		}
		else if($min<1)
		{
			$max+=(0-$min+1);
			$min=1;
		}
		else if($max>ceil($count/ROW_PER_PAGE))
		{
			$min-=($max-ceil($count/ROW_PER_PAGE));
			$max=ceil($count/ROW_PER_PAGE);
		}
		?>
		
		<?php for($j=$min;$j<=$max;$j++){?>
			<?php if($i==$j){?>
			<a id='current'><span class='number' ><?php echo $j;?></span></a>
			<?php }else{?>
			<span class='number' onclick="window.location='index.php?page=<?php echo $page?>&i=<?php echo $j?>'" ><?php echo $j;?></span>
			<?php }?>
		<?php }	?> 
		
		<?php if($i<ceil($count/ROW_PER_PAGE)){?><span onclick="window.location='index.php?page=<?php echo $page?>&i=<?php echo $i+1?>'" title='Trang tiếp theo' id='next'></span><?php }?>
	</div>
	
	<a href="#body">Về đầu trang</a>
</div>
</div>
</div>
